{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json\n",
    "import numpy as np\n",
    "import pickle\n",
    "from collections import defaultdict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_tvshows() -> dict:\n",
    "    # 从服务器获取电视剧信息\n",
    "    url = 'http://192.168.2.138:8080/jsonrpc'\n",
    "    parameters = {\n",
    "                  \"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.GetTVShows\", \n",
    "                  \"params\": { \n",
    "                      \"properties\": [ \"title\", \"originaltitle\",  \"playcount\", \"file\", \"season\", \"episode\"], \n",
    "                      \"sort\": { \"order\": \"ascending\", \"method\": \"label\" } \n",
    "                  }, \n",
    "                  \"id\": \"libTvShows\"\n",
    "                 }\n",
    "    json_all_tvshows = requests.post(url,json=parameters,auth=(\"kodi\",\"kodi\")).json()\n",
    "    dict_all_tvshows = dict()\n",
    "    for itvshow in json_all_tvshows['result']['tvshows']:\n",
    "        # store tvshowid , number of seasons, number of total episode\n",
    "        tvshow_info = dict()\n",
    "        tvshow_info['basic'] = ((itvshow['tvshowid'],itvshow['season'],itvshow['episode']))\n",
    "        # get all episode id into a array\n",
    "        parameters2 = {\n",
    "                  \"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.GetEpisodes\", \n",
    "                  \"params\": { \n",
    "                      \"tvshowid\":itvshow['tvshowid'],\n",
    "                      \"properties\": [\"title\", \"originaltitle\", \"season\", \"file\",\"episode\",\"showtitle\"], \n",
    "    #                   \"limits\": { \"start\" : 0, \"end\": 75 }, \n",
    "                      \"sort\": { \"order\": \"ascending\", \"method\": \"label\" } \n",
    "                  }, \n",
    "                  \"id\": \"libEpisodes\"\n",
    "                 }\n",
    "        json_episodes = requests.post(url,json=parameters2,auth=(\"kodi\",\"kodi\")).json()\n",
    "    #    print(itvshow['title'],json_episodes['result'].keys())\n",
    "    #     episodes_id = np.zeros((itvshow['season'],itvshow['episode']))\n",
    "        try:\n",
    "            episodes = [(iepisode['season'],iepisode['episode'],iepisode['episodeid']) for iepisode in json_episodes['result']['episodes']]\n",
    "            tvshow_info['detail'] = episodes\n",
    "            episodes_index = defaultdict(list)\n",
    "            for ie in episodes:\n",
    "                if ie[1] == len(episodes_index[f\"{ie[0]:04d}\"])+1:\n",
    "                    episodes_index[f\"{ie[0]:04d}\"].append(ie[2])\n",
    "                else:\n",
    "                    # 如果下一个的episode和已经存储的不连续，那么先添加-1填充\n",
    "                    for i in range(ie[1] - len(episodes_index[f\"{ie[0]:04d}\"]) -1 ):\n",
    "                        episodes_index[f\"{ie[0]:04d}\"].append(-1)\n",
    "                    episodes_index[f\"{ie[0]:04d}\"].append(ie[2])\n",
    "\n",
    "            tvshow_info['index'] = episodes_index        \n",
    "            dict_all_tvshows[itvshow['title']] = tvshow_info   \n",
    "        except Exception as e:\n",
    "            print(itvshow['title'])\n",
    "            print(e.message)\n",
    "    return dict_all_tvshows\n",
    "\n",
    "\n",
    "def store(data):\n",
    "    # save result\n",
    "    with open(\"dict_all_tvshows\",\"wb\") as f:\n",
    "        pickle.dump(data,f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dict_all_tvshows = get_tvshows()\n",
    "store(dict_all_tvshows)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def read_data():\n",
    "    with open(\"dict_all_tvshows\",\"rb\") as f:\n",
    "        result = pickle.load(f)\n",
    "    return result\n",
    "\n",
    "dict_all_tvshows = read_data()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def calc_index(data):\n",
    "    # calculate the index for dict_all_tvshows\n",
    "    for ishow in data:\n",
    "        episodes = defaultdict(list)\n",
    "        for ie in data[ishow]['detail']:\n",
    "            if ie[1] == len(episodes[f\"{ie[0]:04d}\"])+1:\n",
    "                episodes[f\"{ie[0]:04d}\"].append(ie[2])\n",
    "            else:\n",
    "                # 如果下一个的episode和已经存储的不连续，那么先添加-1填充\n",
    "                for i in range(ie[1] - len(episodes[f\"{ie[0]:04d}\"]) -1 ):\n",
    "                    episodes[f\"{ie[0]:04d}\"].append(-1)\n",
    "                episodes[f\"{ie[0]:04d}\"].append(ie[2])\n",
    "\n",
    "        data[ishow]['index'] = episodes\n",
    "    return data\n",
    "\n",
    "dict_all_tvshows = calc_index(dict_all_tvshows)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['9号秘事', '与霍金一起了解宇宙', '了不起的麦瑟尔夫人', '使女的故事', '全裸导演', '冰血暴', '副总统', '十二猴子', '城堡岩', '大明王朝1566', '大西洋帝国', '奥丽芙·基特里奇', '好汉两个半', '孤独的美食家', '宋飞正传', '小谢尔顿', '怪奇物语', '恶搞之家', '摩登家庭', '斯巴达克斯', '无人生还', '早间新闻', '是，大臣', '是，首相', '最完美的离婚', '权力的游戏', '毒枭', '深夜食堂', '火线', '爱，死亡和机器人', '特工科恩', '王朝', '瑞克和莫蒂', '生活大爆炸', '真探', '硅谷', '神探夏洛克', '禁忌', '红楼梦', '纸牌屋', '绝命毒师', '维多利亚的秘密时尚秀', '罗马', '老友记', '老爸老妈的浪漫史', '致命女人', '走向共和', '越野千里', '降世神通：最后的气宗', '降世神通：科拉传奇', '风骚律师', '飞出个未来', '飞天大盗', '马男波杰克', '黑吃黑', '黑道家族', '黑钱胜地', '黑镜'])"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict_all_tvshows.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['limits', 'tvshows'])"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "{'end': 39, 'start': 0, 'total': 39}"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "[(26, '9号秘事', 3, 18),\n",
       " (9, 'silicon vally', 6, 53),\n",
       " (30, '与霍金一起了解宇宙', 1, 1),\n",
       " (39, '副总统', 6, 56),\n",
       " (1, '十二猴子', 1, 13),\n",
       " (4, '大明王朝1566', 1, 46),\n",
       " (38, '大西洋帝国', 5, 56),\n",
       " (23, '奥丽芙·基特里奇', 1, 4),\n",
       " (3, '孤独的美食家', 1, 12),\n",
       " (6, '宋飞正传', 9, 171),\n",
       " (36, '小谢尔顿', 2, 31),\n",
       " (8, '怪奇物语', 1, 8),\n",
       " (19, '斯巴达克斯', 3, 32),\n",
       " (33, '早间新闻', 1, 10),\n",
       " (12, '是，大臣', 3, 44),\n",
       " (28, '是，首相', 3, 17),\n",
       " (16, '最完美的离婚', 2, 13),\n",
       " (24, '权力的游戏', 8, 73),\n",
       " (11, '深夜食堂', 3, 40),\n",
       " (27, '深夜食堂', 4, 50),\n",
       " (18, '火线', 5, 60),\n",
       " (17, '爱，死亡和机器人', 1, 18),\n",
       " (32, '王朝', 1, 5),\n",
       " (34, '生活大爆炸', 4, 79),\n",
       " (7, '神探夏洛克', 1, 6),\n",
       " (2, '红楼梦', 1, 76),\n",
       " (20, '纸牌屋', 5, 59),\n",
       " (5, '维多利亚的秘密时尚秀', 1, 11),\n",
       " (13, '老友记', 10, 234),\n",
       " (15, '老爸老妈的浪漫史', 0, 0),\n",
       " (31, '致命女人', 1, 10),\n",
       " (10, '走向共和', 2, 70),\n",
       " (14, '降世神通：最后的气宗', 3, 39),\n",
       " (37, '降世神通：科拉传奇', 4, 52),\n",
       " (29, '风骚律师', 5, 49),\n",
       " (22, '飞出个未来', 5, 78),\n",
       " (25, '马男波杰克', 1, 22),\n",
       " (21, '黑吃黑', 2, 40),\n",
       " (35, '黑道家族', 6, 86)]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result['result'].keys()\n",
    "result['result']['limits']\n",
    "[(i['tvshowid'],i['title'],i['season'],i['episode']) for i in result['result']['tvshows']]\n",
    "# set([i['tvshowid'] for i in result['result']['tvshows']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'episode': 1,\n",
       "  'episodeid': 313,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S01/硅谷.Silicon.Valley.S01E01.2014.BD.MiniSD-TLF.mkv',\n",
       "  'label': '1x01. 硅谷.Silicon.Valley.S01E01.2014.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 1,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S01E01.2014.BD.MiniSD-TLF'},\n",
       " {'episode': 2,\n",
       "  'episodeid': 314,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S01/硅谷.Silicon.Valley.S01E02.2014.BD.MiniSD-TLF.mkv',\n",
       "  'label': '1x02. 硅谷.Silicon.Valley.S01E02.2014.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 1,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S01E02.2014.BD.MiniSD-TLF'},\n",
       " {'episode': 3,\n",
       "  'episodeid': 315,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S01/硅谷.Silicon.Valley.S01E03.2014.BD.MiniSD-TLF.mkv',\n",
       "  'label': '1x03. 硅谷.Silicon.Valley.S01E03.2014.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 1,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S01E03.2014.BD.MiniSD-TLF'},\n",
       " {'episode': 4,\n",
       "  'episodeid': 316,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S01/硅谷.Silicon.Valley.S01E04.2014.BD.MiniSD-TLF.mkv',\n",
       "  'label': '1x04. 硅谷.Silicon.Valley.S01E04.2014.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 1,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S01E04.2014.BD.MiniSD-TLF'},\n",
       " {'episode': 5,\n",
       "  'episodeid': 317,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S01/硅谷.Silicon.Valley.S01E05.2014.BD.MiniSD-TLF.mkv',\n",
       "  'label': '1x05. 硅谷.Silicon.Valley.S01E05.2014.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 1,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S01E05.2014.BD.MiniSD-TLF'},\n",
       " {'episode': 6,\n",
       "  'episodeid': 318,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S01/硅谷.Silicon.Valley.S01E06.2014.BD.MiniSD-TLF.mkv',\n",
       "  'label': '1x06. 硅谷.Silicon.Valley.S01E06.2014.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 1,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S01E06.2014.BD.MiniSD-TLF'},\n",
       " {'episode': 7,\n",
       "  'episodeid': 319,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S01/硅谷.Silicon.Valley.S01E07.2014.BD.MiniSD-TLF.mkv',\n",
       "  'label': '1x07. 硅谷.Silicon.Valley.S01E07.2014.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 1,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S01E07.2014.BD.MiniSD-TLF'},\n",
       " {'episode': 8,\n",
       "  'episodeid': 320,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S01/硅谷.Silicon.Valley.S01E08.2014.BD.MiniSD-TLF.mkv',\n",
       "  'label': '1x08. 硅谷.Silicon.Valley.S01E08.2014.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 1,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S01E08.2014.BD.MiniSD-TLF'},\n",
       " {'episode': 1,\n",
       "  'episodeid': 321,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S02/硅谷.Silicon.Valley.S02E01.2015.BD.MiniSD-TLF.mkv',\n",
       "  'label': '2x01. 硅谷.Silicon.Valley.S02E01.2015.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 2,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S02E01.2015.BD.MiniSD-TLF'},\n",
       " {'episode': 2,\n",
       "  'episodeid': 322,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S02/硅谷.Silicon.Valley.S02E02.2015.BD.MiniSD-TLF.mkv',\n",
       "  'label': '2x02. 硅谷.Silicon.Valley.S02E02.2015.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 2,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S02E02.2015.BD.MiniSD-TLF'},\n",
       " {'episode': 3,\n",
       "  'episodeid': 323,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S02/硅谷.Silicon.Valley.S02E03.2015.BD.MiniSD-TLF.mkv',\n",
       "  'label': '2x03. 硅谷.Silicon.Valley.S02E03.2015.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 2,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S02E03.2015.BD.MiniSD-TLF'},\n",
       " {'episode': 4,\n",
       "  'episodeid': 324,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S02/硅谷.Silicon.Valley.S02E04.2015.BD.MiniSD-TLF.mkv',\n",
       "  'label': '2x04. 硅谷.Silicon.Valley.S02E04.2015.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 2,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S02E04.2015.BD.MiniSD-TLF'},\n",
       " {'episode': 5,\n",
       "  'episodeid': 325,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S02/硅谷.Silicon.Valley.S02E05.2015.BD.MiniSD-TLF.mkv',\n",
       "  'label': '2x05. 硅谷.Silicon.Valley.S02E05.2015.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 2,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S02E05.2015.BD.MiniSD-TLF'},\n",
       " {'episode': 6,\n",
       "  'episodeid': 326,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S02/硅谷.Silicon.Valley.S02E06.2015.BD.MiniSD-TLF.mkv',\n",
       "  'label': '2x06. 硅谷.Silicon.Valley.S02E06.2015.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 2,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S02E06.2015.BD.MiniSD-TLF'},\n",
       " {'episode': 7,\n",
       "  'episodeid': 327,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S02/硅谷.Silicon.Valley.S02E07.2015.BD.MiniSD-TLF.mkv',\n",
       "  'label': '2x07. 硅谷.Silicon.Valley.S02E07.2015.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 2,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S02E07.2015.BD.MiniSD-TLF'},\n",
       " {'episode': 8,\n",
       "  'episodeid': 328,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S02/硅谷.Silicon.Valley.S02E08.2015.BD.MiniSD-TLF.mkv',\n",
       "  'label': '2x08. 硅谷.Silicon.Valley.S02E08.2015.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 2,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S02E08.2015.BD.MiniSD-TLF'},\n",
       " {'episode': 9,\n",
       "  'episodeid': 329,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S02/硅谷.Silicon.Valley.S02E09.2015.BD.MiniSD-TLF.mkv',\n",
       "  'label': '2x09. 硅谷.Silicon.Valley.S02E09.2015.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 2,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S02E09.2015.BD.MiniSD-TLF'},\n",
       " {'episode': 10,\n",
       "  'episodeid': 330,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S02/硅谷.Silicon.Valley.S02E10.2015.BD.MiniSD-TLF.mkv',\n",
       "  'label': '2x10. 硅谷.Silicon.Valley.S02E10.2015.BD.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 2,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S02E10.2015.BD.MiniSD-TLF'},\n",
       " {'episode': 1,\n",
       "  'episodeid': 331,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S03/硅谷.第3季.Silicon.Valley.S03E01.2016.HDTV.MiniHD-TLF.mkv',\n",
       "  'label': '3x01. 硅谷.第3季.Silicon.Valley.S03E01.2016.HDTV.MiniHD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 3,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.第3季.Silicon.Valley.S03E01.2016.HDTV.MiniHD-TLF'},\n",
       " {'episode': 2,\n",
       "  'episodeid': 332,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S03/硅谷.第3季.Silicon.Valley.S03E02.2016.HDTV.MiniHD-TLF.mkv',\n",
       "  'label': '3x02. 硅谷.第3季.Silicon.Valley.S03E02.2016.HDTV.MiniHD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 3,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.第3季.Silicon.Valley.S03E02.2016.HDTV.MiniHD-TLF'},\n",
       " {'episode': 3,\n",
       "  'episodeid': 333,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S03/硅谷.第3季.Silicon.Valley.S03E03.2016.HDTV.MiniHD-TLF.mkv',\n",
       "  'label': '3x03. 硅谷.第3季.Silicon.Valley.S03E03.2016.HDTV.MiniHD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 3,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.第3季.Silicon.Valley.S03E03.2016.HDTV.MiniHD-TLF'},\n",
       " {'episode': 4,\n",
       "  'episodeid': 334,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S03/硅谷.第3季.Silicon.Valley.S03E04.2016.HDTV.MiniHD-TLF.mkv',\n",
       "  'label': '3x04. 硅谷.第3季.Silicon.Valley.S03E04.2016.HDTV.MiniHD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 3,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.第3季.Silicon.Valley.S03E04.2016.HDTV.MiniHD-TLF'},\n",
       " {'episode': 5,\n",
       "  'episodeid': 335,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S03/硅谷.第3季.Silicon.Valley.S03E05.2016.HDTV.MiniHD-TLF.mkv',\n",
       "  'label': '3x05. 硅谷.第3季.Silicon.Valley.S03E05.2016.HDTV.MiniHD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 3,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.第3季.Silicon.Valley.S03E05.2016.HDTV.MiniHD-TLF'},\n",
       " {'episode': 6,\n",
       "  'episodeid': 336,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S03/硅谷.第3季.Silicon.Valley.S03E06.2016.HDTV.MiniHD-TLF.mkv',\n",
       "  'label': '3x06. 硅谷.第3季.Silicon.Valley.S03E06.2016.HDTV.MiniHD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 3,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.第3季.Silicon.Valley.S03E06.2016.HDTV.MiniHD-TLF'},\n",
       " {'episode': 7,\n",
       "  'episodeid': 337,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S03/硅谷.第3季.Silicon.Valley.S03E07.2016.HDTV.MiniHD-TLF.mkv',\n",
       "  'label': '3x07. 硅谷.第3季.Silicon.Valley.S03E07.2016.HDTV.MiniHD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 3,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.第3季.Silicon.Valley.S03E07.2016.HDTV.MiniHD-TLF'},\n",
       " {'episode': 8,\n",
       "  'episodeid': 338,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S03/硅谷.第3季.Silicon.Valley.S03E08.2016.HDTV.MiniHD-TLF.mkv',\n",
       "  'label': '3x08. 硅谷.第3季.Silicon.Valley.S03E08.2016.HDTV.MiniHD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 3,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.第3季.Silicon.Valley.S03E08.2016.HDTV.MiniHD-TLF'},\n",
       " {'episode': 9,\n",
       "  'episodeid': 339,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S03/硅谷.第3季.Silicon.Valley.S03E09.2016.HDTV.MiniHD-TLF.mkv',\n",
       "  'label': '3x09. 硅谷.第3季.Silicon.Valley.S03E09.2016.HDTV.MiniHD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 3,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.第3季.Silicon.Valley.S03E09.2016.HDTV.MiniHD-TLF'},\n",
       " {'episode': 10,\n",
       "  'episodeid': 340,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S03/硅谷.第3季.Silicon.Valley.S03E10.2016.HDTV.MiniHD-TLF.mkv',\n",
       "  'label': '3x10. 硅谷.第3季.Silicon.Valley.S03E10.2016.HDTV.MiniHD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 3,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.第3季.Silicon.Valley.S03E10.2016.HDTV.MiniHD-TLF'},\n",
       " {'episode': 1,\n",
       "  'episodeid': 303,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/Silicon.Valley.S04.2017.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S04E01.Success.Failure.2017.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '4x01. 硅谷.Silicon.Valley.S04E01.Success.Failure.2017.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 4,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S04E01.Success.Failure.2017.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 2,\n",
       "  'episodeid': 304,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/Silicon.Valley.S04.2017.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S04E02.Terms.Of.Service.2017.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '4x02. 硅谷.Silicon.Valley.S04E02.Terms.Of.Service.2017.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 4,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S04E02.Terms.Of.Service.2017.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 3,\n",
       "  'episodeid': 305,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/Silicon.Valley.S04.2017.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S04E03.Intellectual.Property.2017.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '4x03. 硅谷.Silicon.Valley.S04E03.Intellectual.Property.2017.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 4,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S04E03.Intellectual.Property.2017.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 4,\n",
       "  'episodeid': 306,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/Silicon.Valley.S04.2017.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S04E04.Teambuilding.Exercise.2017.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '4x04. 硅谷.Silicon.Valley.S04E04.Teambuilding.Exercise.2017.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 4,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S04E04.Teambuilding.Exercise.2017.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 5,\n",
       "  'episodeid': 307,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/Silicon.Valley.S04.2017.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S04E05.The.Blood.Boy.2017.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '4x05. 硅谷.Silicon.Valley.S04E05.The.Blood.Boy.2017.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 4,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S04E05.The.Blood.Boy.2017.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 6,\n",
       "  'episodeid': 308,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/Silicon.Valley.S04.2017.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S04E06.Customer.Service.2017.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '4x06. 硅谷.Silicon.Valley.S04E06.Customer.Service.2017.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 4,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S04E06.Customer.Service.2017.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 7,\n",
       "  'episodeid': 309,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/Silicon.Valley.S04.2017.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S04E07.The.Patent.Troll.2017.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '4x07. 硅谷.Silicon.Valley.S04E07.The.Patent.Troll.2017.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 4,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S04E07.The.Patent.Troll.2017.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 8,\n",
       "  'episodeid': 310,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/Silicon.Valley.S04.2017.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S04E08.The.Keenan.Vortex.2017.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '4x08. 硅谷.Silicon.Valley.S04E08.The.Keenan.Vortex.2017.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 4,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S04E08.The.Keenan.Vortex.2017.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 9,\n",
       "  'episodeid': 311,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/Silicon.Valley.S04.2017.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S04E09.Hooli-Con.2017.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '4x09. 硅谷.Silicon.Valley.S04E09.Hooli-Con.2017.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 4,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S04E09.Hooli-Con.2017.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 10,\n",
       "  'episodeid': 312,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/Silicon.Valley.S04.2017.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S04E10.Server.Error.2017.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '4x10. 硅谷.Silicon.Valley.S04E10.Server.Error.2017.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 4,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S04E10.Server.Error.2017.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 1,\n",
       "  'episodeid': 341,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S05.2018.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S05E01.2018.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '5x01. 硅谷.Silicon.Valley.S05E01.2018.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 5,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S05E01.2018.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 2,\n",
       "  'episodeid': 342,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S05.2018.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S05E02.2018.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '5x02. 硅谷.Silicon.Valley.S05E02.2018.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 5,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S05E02.2018.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 3,\n",
       "  'episodeid': 343,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S05.2018.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S05E03.2018.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '5x03. 硅谷.Silicon.Valley.S05E03.2018.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 5,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S05E03.2018.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 4,\n",
       "  'episodeid': 344,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S05.2018.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S05E04.2018.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '5x04. 硅谷.Silicon.Valley.S05E04.2018.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 5,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S05E04.2018.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 5,\n",
       "  'episodeid': 345,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S05.2018.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S05E05.2018.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '5x05. 硅谷.Silicon.Valley.S05E05.2018.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 5,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S05E05.2018.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 6,\n",
       "  'episodeid': 346,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S05.2018.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S05E06.2018.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '5x06. 硅谷.Silicon.Valley.S05E06.2018.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 5,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S05E06.2018.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 7,\n",
       "  'episodeid': 347,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S05.2018.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S05E07.2018.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '5x07. 硅谷.Silicon.Valley.S05E07.2018.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 5,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S05E07.2018.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 8,\n",
       "  'episodeid': 348,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S05.2018.WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S05E08.2018.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '5x08. 硅谷.Silicon.Valley.S05E08.2018.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 5,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S05E08.2018.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 1,\n",
       "  'episodeid': 349,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S06.2019..WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S06E01.Artificial.Lack.of.Intelligence.2019..WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '6x01. 硅谷.Silicon.Valley.S06E01.Artificial.Lack.of.Intelligence.2019..WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 6,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S06E01.Artificial.Lack.of.Intelligence.2019..WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 2,\n",
       "  'episodeid': 350,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S06.2019..WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S06E02.Blood.Money.2019.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '6x02. 硅谷.Silicon.Valley.S06E02.Blood.Money.2019.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 6,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S06E02.Blood.Money.2019.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 3,\n",
       "  'episodeid': 351,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S06.2019..WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S06E03.Hooli.Smokes.2019.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '6x03. 硅谷.Silicon.Valley.S06E03.Hooli.Smokes.2019.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 6,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S06E03.Hooli.Smokes.2019.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 4,\n",
       "  'episodeid': 352,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S06.2019..WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S06E04.Maximizing.Alphaness.2019.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '6x04. 硅谷.Silicon.Valley.S06E04.Maximizing.Alphaness.2019.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 6,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S06E04.Maximizing.Alphaness.2019.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 5,\n",
       "  'episodeid': 353,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S06.2019..WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S06E05.Tethics.2019.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '6x05. 硅谷.Silicon.Valley.S06E05.Tethics.2019.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 6,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S06E05.Tethics.2019.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 6,\n",
       "  'episodeid': 354,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S06.2019..WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S06E06.RussFest.2019.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '6x06. 硅谷.Silicon.Valley.S06E06.RussFest.2019.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 6,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S06E06.RussFest.2019.WEB-DL.MiniSD-TLF'},\n",
       " {'episode': 7,\n",
       "  'episodeid': 355,\n",
       "  'file': 'nfs://192.168.2.164/mnt/sata1/剧集/silicon.vally.硅谷/硅谷.Silicon.Valley.S06.2019..WEB-DL.MiniSD-TLF/硅谷.Silicon.Valley.S06E07.Exit.Event.2019.WEB-DL.MiniSD-TLF.mkv',\n",
       "  'label': '6x07. 硅谷.Silicon.Valley.S06E07.Exit.Event.2019.WEB-DL.MiniSD-TLF',\n",
       "  'originaltitle': '',\n",
       "  'season': 6,\n",
       "  'showtitle': 'silicon vally',\n",
       "  'title': '硅谷.Silicon.Valley.S06E07.Exit.Event.2019.WEB-DL.MiniSD-TLF'}]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "{'end': 53, 'start': 0, 'total': 53}"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result2['result']['episodes']\n",
    "result2['result']['limits']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'id': 1, 'jsonrpc': '2.0', 'result': 'OK'}"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def play_episode(episodeid: int) -> str:\n",
    "    parameters3 = {\n",
    "              \"jsonrpc\": \"2.0\", \"method\": \"Player.Open\", \n",
    "              \"params\": {\n",
    "                  \"item\":{\"episodeid\":episodeid}                  \n",
    "                }, \n",
    "              \"id\": 1\n",
    "             }\n",
    "\n",
    "    result3= requests.post(url,json=parameters3,auth=(\"kodi\",\"kodi\")).json()\n",
    "    return result3['result']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'id': 1,\n",
       " 'jsonrpc': '2.0',\n",
       " 'result': [{'playerid': 1, 'playertype': 'internal', 'type': 'video'}]}"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parameters4 = {\n",
    "              \"jsonrpc\": \"2.0\", \"method\": \"Player.GetActivePlayers\", \n",
    "              \"params\": {\n",
    "                  \n",
    "                }, \n",
    "              \"id\": 1\n",
    "             }\n",
    "\n",
    "result4= requests.post(url,json=parameters4,auth=(\"kodi\",\"kodi\")).json()\n",
    "result4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "parameters5 = {\n",
    "              \"jsonrpc\": \"2.0\", \"method\": \"Player.Stop\", \n",
    "              \"params\": {\n",
    "                  \"playerid\":1\n",
    "                }, \n",
    "              \"id\": 1\n",
    "             }\n",
    "\n",
    "result5= requests.post(url,json=parameters5,auth=(\"kodi\",\"kodi\")).json()\n",
    "result5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'id': 1, 'jsonrpc': '2.0', 'result': 'OK'}"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def scan_library():\n",
    "    parameters6 = {\n",
    "              \"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.Scan\", \n",
    "              \"params\": {                  \n",
    "                }, \n",
    "              \"id\": 1\n",
    "             }\n",
    "\n",
    "    result6= requests.post(url,json=parameters6,auth=(\"kodi\",\"kodi\")).json()\n",
    "    return result6[\"result\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "\n",
    "def parse_play(command):\n",
    "    tvshow = None\n",
    "    season = None\n",
    "    episode = None\n",
    "    pattern = re.compile(\"播放(.*)\")\n",
    "    pattern_episode = re.compile(\"(.*)第(.*)集\")\n",
    "    pattern_season = re.compile(\"(.*)第(.*)季\")\n",
    "    match_play = pattern.search(command)\n",
    "    if match_play:\n",
    "        whatplay = match_play.groups()[0]\n",
    "        match_episode = pattern_episode.search(whatplay)\n",
    "        if match_episode:\n",
    "            episode = match_episode.groups()[1]\n",
    "            whatplay = match_episode.groups()[0]\n",
    "        match_season = pattern_season.search(whatplay)\n",
    "        if match_season:\n",
    "            season = match_season.groups()[1]\n",
    "            tvshow = match_season.groups()[0]\n",
    "        else:\n",
    "            tvshow = whatplay\n",
    "        return [tvshow,season,episode]\n",
    "    else:\n",
    "        # 没找到播放关键字\n",
    "        return None\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1])"
      ]
     },
     "execution_count": 133,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(1,3,size=1)\n",
    "# np.random.randint?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 1, 1, 1])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# np.dot(np.array([1]).reshape(2,1),np.array([10,1]))\n",
    "np.pad(np.array([1]),(3,0),'constant',constant_values=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'hello'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-61-c6c342b3cf04>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtest\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'hello'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m: 'hello'"
     ]
    }
   ],
   "source": [
    "dict(test=2,name=3)['hello']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def number(n_str:str) -> int:\n",
    "    # turn string number into int, string number could be chinese character\n",
    "    chinese_num = [\"零\",\"一\",\"二\",\"三\",\"四\",\"五\",\"六\",\"七\",\"八\",\"九\",\"十\",\"百\",\"千\",\"万\"]\n",
    "    num  = [0,1,2,3,4,5,6,7,8,9,10,100,1000,10000]\n",
    "    try:\n",
    "        result = int(n_str)\n",
    "    except ValueError:\n",
    "        # for chinese character\n",
    "        num_digit = [] # 位上的数字\n",
    "        num_multy = [] # 乘子\n",
    "        for i,istr in enumerate(n_str):\n",
    "            try:\n",
    "                if chinese_num.index(istr)<=9:\n",
    "                    num_digit.append(num[chinese_num.index(istr)])                          \n",
    "                else:\n",
    "                    num_multy.append(num[chinese_num.index(istr)])\n",
    "            except ValueError:\n",
    "                # the character is not in chinese_num,return 1 for robust\n",
    "                return 1\n",
    "            if i==len(n_str)-1:\n",
    "                num_multy.append(1)\n",
    "        num_digit = np.pad(np.array(num_digit),(len(num_multy)-len(num_digit),0),'constant',constant_values=1)\n",
    "        num_multy = np.array(num_multy)\n",
    "        result = np.dot(num_digit,num_multy)\n",
    "    return result\n",
    "\n",
    "number(\"十无\")\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'老爸老妈的浪漫史'"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def parse_tvshow_name(name:str) ->str:\n",
    "    # 把口语上的剧集名字转换为数据库中的名字\n",
    "    oral_names = {\n",
    "        \"六人行\":\"老友记\",\n",
    "        \"寻妈记\":\"老爸老妈的浪漫史\",\n",
    "        \"老爸老妈\":\"老爸老妈的浪漫史\",\n",
    "        \"宋飞\":\"宋飞正传\",\n",
    "        \"爱死机\":\"爱，死亡和机器人\",\n",
    "        \"大臣\":\"是，大臣\",\n",
    "        \"首相\":\"是，首相\", \n",
    "    }\n",
    "    try:\n",
    "        database_name = oral_names[name]\n",
    "    except KeyError as e:\n",
    "        print(f\"{name} is not in oral names dict\")\n",
    "        database_name = name\n",
    "    return database_name\n",
    "\n",
    "parse_tvshow_name(\"寻妈记\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['六人行', '三', '五']\n",
      "['老友记', '3', None]\n",
      "['老友记', None, '9']\n",
      "['六人行', None, None]\n"
     ]
    }
   ],
   "source": [
    "print(parse_play(command))\n",
    "print(parse_play(command2))\n",
    "print(parse_play(command3))\n",
    "print(parse_play(\"播放六人行\"))\n",
    "def get_episodeid(command):\n",
    "    result = parse_play(command)\n",
    "    if result[0] is None:\n",
    "        return None,\"Error\"\n",
    "    else:\n",
    "        tvshow_name = parse_tvshow_name(result[0])\n",
    "        if tvshow_name in dict_all_tvshows.keys():\n",
    "            if result[1] is None:\n",
    "                # play random episode\n",
    "                pick = np.random.randint(0,len(dict_all_tvshows[tvshow_name]['detail']),size=(1))[0]\n",
    "                return dict_all_tvshows[tvshow_name]['detail'][pick][2],f\"播放{tvshow_name}第{dict_all_tvshows[tvshow_name]['detail'][pick][0]}季第{dict_all_tvshows[tvshow_name]['detail'][pick][1]}集\"\n",
    "            else:\n",
    "                ns = number(result[1])\n",
    "                if result[2] is None:\n",
    "                    # play random episode for the given season\n",
    "                    episodeid = np.random.choice(dict_all_tvshows[tvshow_name]['index'][f\"{ns:04d}\"])\n",
    "                    return episodeid,f\"播放{tvshow_name}第{ns}季第{dict_all_tvshows[tvshow_name]['index'][f'{ns:04d}'].index(episodeid)}集\"\n",
    "                else:\n",
    "                    # play given episode from given season                  \n",
    "                    ne = number(result[2])\n",
    "                    episodeid = dict_all_tvshows[tvshow_name]['index'][f'{ns:04d}'][ne-1]\n",
    "                    return episodeid,f\"播放{tvshow_name}第{ns}季第{ne}集\"\n",
    "\n",
    "        else:\n",
    "            return None,\"Error\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2570, '播放老友记第3季第5集')"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "老友记 is not in oral names dict\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(2577, '播放老友记第3季第11集')"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "老友记 is not in oral names dict\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(2547, '播放老友记第2季第6集')"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command = \"播放六人行第三季第五集\"\n",
    "command2 = \"播放老友记第3季\"\n",
    "command3 = \"播放老友记第9集\"\n",
    "get_episodeid(command)\n",
    "get_episodeid(command2)\n",
    "get_episodeid(command3)"
   ]
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
